﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       App_Commons_RoomSearch
 * 类型：       房间信息检索
 * 功能说明：   检索
 * 作者：       谈震鸣
 * 创建日期：   2007/08/20
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
 */
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.App.Master.Dao;
using Shpm.App.Input.Dao;
using Shpm.App.Master.Bean;
using Shpm.System;

public partial class App_Commons_CustomerSearch : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            GridView1.DataSourceID = null;
            SetCmbSex();
        }
    }
    protected void btnSeach_Click(object sender, EventArgs e)
    {
        if (ComValidator1.DoValidator())
        {
            ViewState["COMMAND"] = "SEARCH";
            this.GridView1.PageIndex = 0;

        }
        else 
        {
            this.GridView1.DataSource = null;
        }
    }
    //设置性别
    private void SetCmbSex()
    {
        CommonDictionaryBean paramBean = new CommonDictionaryBean();
        paramBean.Catalog = "SEX";
        CommonDictionaryDao dao = new CommonDictionaryDao();
        IList dataList = dao.FindByCatalog(paramBean);
        cmbSex.DataSource = dataList;
        cmbSex.DataBind();
        if (SetCmbIndex(dataList) != -1)
            cmbSex.SelectedIndex = SetCmbIndex(dataList);
    }

    //设置下拉框的默认值
    private int SetCmbIndex(IList list)
    {
        CommonDictionaryBean dataBean = new CommonDictionaryBean();
        for (int i = 0; i < list.Count; i++)
        {
            dataBean = (CommonDictionaryBean)list[i];
            if (dataBean.Default == true) return i;
        }
        return -1;
    }


    #region 取得数据字典的内容
    //取得数据字典的内容
    private string GetDocData(string str1, string str2)
    {
        CommonDictionaryBean dataBean = new CommonDictionaryBean();
        CommonDictionaryDao Dao = new CommonDictionaryDao();
        dataBean.Catalog = str1;
        dataBean.DictNo = str2;
        dataBean = Dao.Load(dataBean);
        if (dataBean != null && dataBean.Content != null) return dataBean.Content;
        else return string.Empty;
    }
    #endregion

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            PersonTableBean bean = (PersonTableBean)e.Row.DataItem;
            (e.Row.FindControl("selectImg") as ImageButton).Attributes.Add("onclick", "selectPerson('" + bean.PersonId + "','" + bean.NameC + "')");
        }
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // 设置分页编号
        GridView1.PageIndex = e.NewPageIndex;
    }

    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        if (ViewState["COMMAND"] != null)
        {
            PersonInfoDao dao = new PersonInfoDao();
            PersonTableBean bean = new PersonTableBean();
            if (!string.IsNullOrEmpty(this.txtPersonId.Text))
            {
                bean.PersonId = new Nullable<int>(Convert.ToInt32(this.txtPersonId.Text));
            }
            bean.NameC = (string.IsNullOrEmpty(this.txtName.Text)) ? null : this.txtName.Text;
            bean.Sex = this.cmbSex.SelectedIndex == -1 || "00".Equals(this.cmbSex.SelectedValue) ? null : this.cmbSex.SelectedValue;

            IList list = dao.FindAll(bean);


            GridView1.DataSource = list;
            GridView1.DataBind();

            if (list.Count == 0)
            {

            }
        }
       
    }

}
